import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbfdsys } from '../../../atoms/db';

const logger = anylogger('pages/api/introduction/query.api');

export type Result = {
	desc: string;
};

export type Message = void;

/**
 * pages/api/introduction/query.api
 */
const handler = an48<Result>();

const key = 'desc';

handler.get(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const r = await tbfdsys().first('value').where({
			key
		});

		const desc = r?.value || '';
		res.status(200).json({
			desc
		});
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ desc: '' });
	}
});

export const config = {} as PageConfig;

export default handler;
